using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Apache.NMS;

namespace SimpleServiceBus.Endpoints.ActiveMQ.Transport {

    public class ActiveMQConsumerPool {

        //-----< Fields >-----
        //----------------------------------------------------------------------------------        
        private String fId;
        private Dictionary<String, ActiveMQConsumedQueue> fQueues = new Dictionary<string, ActiveMQConsumedQueue>();
        private Dictionary<String, ActiveMQConsumedTopic> fTopics = new Dictionary<string, ActiveMQConsumedTopic>();


        //-----< Constructors >-----
        //----------------------------------------------------------------------------------        
        public ActiveMQConsumerPool(String id) {
            if(String.IsNullOrEmpty(id))
                throw new ArgumentNullException("id");
            fId = id;
            this.WorkerCount = 1;
        }

        //-----< Public and protected properties >-----
        //----------------------------------------------------------------------------------        

        public String Id {
            get { return fId; }
        }

        public AcknowledgementMode AcknowledgementMode {
            get;
            set;
        }

        public Boolean HasQueues {
            get { return fQueues.Count > 0; }
        }

        public Boolean HasTopics {
            get { return fTopics.Count > 0; }
        }

        /// <summary>
        /// Enables or disables exclusive consumers when using queues. An exclusive consumer means
        /// only one instance of a consumer is allowed to process messages on a queue to preserve order
        /// </summary>
        public Boolean IsExclusive {
            get;
            set;
        }

        public IEnumerable<ActiveMQConsumedQueue> Queues {
            get { return fQueues.Values; }
        }

        public IEnumerable<ActiveMQConsumedTopic> Topics {
            get { return fTopics.Values; }
        }

        public Int32 WorkerCount {
            get;
            set;
        }

        //-----< Public and protected methods >-----
        //----------------------------------------------------------------------------------        

        public void AddQueue(ActiveMQConsumedQueue queue) {
            if(queue == null)
                throw new ArgumentNullException("queue");
            fQueues.Add(queue.Name, queue);
        }

        public void AddTopic(ActiveMQConsumedTopic topic) {
            if(topic == null)
                throw new ArgumentNullException("topic");
            fTopics.Add(topic.Name, topic);
        }

        public void RemoveQueue(ActiveMQConsumedQueue queue) {
            if(queue == null)
                throw new ArgumentNullException("queue");
            fQueues.Remove(queue.Name);
        }

        public void RemoveQueue(String name) {
            fQueues.Remove(name);
        }

        public void RemoveTopic(ActiveMQConsumedTopic topic) {
            if(topic == null)
                throw new ArgumentNullException("topic");
            fTopics.Remove(topic.Name);
        }

        public void RemoveTopic(String name) {
            fTopics.Remove(name);
        }

        //-----< Events >-----
        //----------------------------------------------------------------------------------        


        //-----< Internal members >-----
        //----------------------------------------------------------------------------------        


        //-----< Private members >-----
        //----------------------------------------------------------------------------------        


        //-----< All nested types >-----
        //----------------------------------------------------------------------------------        


        //-----< All explicit interface implementations >-----
        //----------------------------------------------------------------------------------        


    }
}

